package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallOrderCouponRefundModel;
import com.mallcloud.mall.mall.service.MallOrderCouponRefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-券订单退款")
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/orderCouponRefund")
public class MallOrderCouponRefundController {
    private final MallOrderCouponRefundService orderCouponRefundService;

    @ApiOperation("分页")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_view')")
    public R<IPage<MallOrderCouponRefundModel>> page(Page page, MallOrderCouponRefundModel orderModel) {
        return R.ok(orderCouponRefundService.page(page, Wrappers.lambdaQuery(orderModel).orderByDesc(MallOrderCouponRefundModel::getCreateTime)));
    }

    @ApiOperation("列表")
    @GetMapping("/list")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_view')")
    public R<List<MallOrderCouponRefundModel>> list(MallOrderCouponRefundModel orderModel) {
        return R.ok(orderCouponRefundService.list(Wrappers.lambdaQuery(orderModel).orderByDesc(MallOrderCouponRefundModel::getCreateTime)));
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_view')")
    public R<MallOrderCouponRefundModel> getById(@PathVariable("id") String id) {
        return R.ok(orderCouponRefundService.getById(id));
    }

    @ApiOperation("新增")
	@PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_add')")
    public R<Boolean> save(@RequestBody MallOrderCouponRefundModel orderModel) {
		return R.ok(orderCouponRefundService.save(orderModel));
    }

    @ApiOperation("修改")
	@PostMapping("/update")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_edit')")
    public R<Boolean> updateById(@RequestBody MallOrderCouponRefundModel orderModel) {
        return R.ok(orderCouponRefundService.updateById(orderModel));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_del')")
    public R<Boolean> removeById(@PathVariable Long id) {
        return R.ok(orderCouponRefundService.removeById(id));
    }

	@ApiOperation("导出")
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('mall_ordercouponrefund_export')")
    public List<MallOrderCouponRefundModel> export(MallOrderCouponRefundModel orderModel) {
        return orderCouponRefundService.list(Wrappers.query(orderModel));
    }
}
